home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Delphi Informant Complete 1995 - 2000
/
Delphi Informant Complete 1995 to 2000.iso
/
Delphi Informant Magazine Complete Works SOURCE CODE 1998.rar
/
1998
/
Jan
/
di9801kw
/
PropExp1.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1997-07-29
|
19KB
|
602 lines
unit PropExp1;
{
Property Explorer.
Request form(s) to search and value to look for,
then display properties that have this name or value.
Written by Keith Wood, 20 March 1997.
Version 1.0
}
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, ToolIntf, StdCtrls, Buttons, ExtCtrls, Grids, EditIntf,
ComCtrls, Menus, ExptIntf;
type
{ The dialog box that is the expert }
TfrmPropExplorerExpert = class(TForm)
Label1: TLabel;
Label2: TLabel;
lbxForms: TListBox;
btnLocate: TBitBtn;
btnCancel: TBitBtn;
hdrResults: THeader;
stgResults: TStringGrid;
Label3: TLabel;
cbxMatchCase: TCheckBox;
cbxWholeWords: TCheckBox;
btnAll: TButton;
btnNone: TButton;
btnShow: TBitBtn;
pnlStatus: TPanel;
ragSearchIn: TRadioGroup;
popAbout: TPopupMenu;
mni1: TMenuItem;
mni3: TMenuItem;
mni2: TMenuItem;
btnSave: TBitBtn;
dlgSave: TSaveDialog;
cmbValue: TComboBox;
procedure hdrResultsSizing(Sender: TObject; ASection, AWidth: Integer);
procedure lbxFormsClick(Sender: TObject);
procedure btnAllClick(Sender: TObject);
procedure btnNoneClick(Sender: TObject);
procedure EnableLocate(Sender: TObject);
procedure btnLocateClick(Sender: TObject);
procedure stgResultsEnter(Sender: TObject);
procedure stgResultsExit(Sender: TObject);
procedure stgResultsDblClick(Sender: TObject);
procedure btnShowClick(Sender: TObject);
procedure btnSaveClick(Sender: TObject);
private
{ Private declarations }
procedure ProcessFiles(sMatchValue: String; lbxForms: TListBox);
public
{ Public declarations }
constructor Create(AOwner: TComponent);
end;
{ Interface procedure from Delphi }
procedure PropExplorerExpert;
implementation
{$R *.DFM}
{ TString -------------------------------------------------------------------- }
type
{ Encapsulate a string in an object }
TString = class
private
FValue: String;
public
constructor Create(sValue: String);
property Value: String read FValue write FValue;
end;
{ Create a new object with an embedded string }
constructor TString.Create(sValue: String);
begin
inherited Create;
FValue := sValue;
end;
{ TfrmPropExplorerExpert ----------------------------------------------------- }
const
cWhiteSpace: set of Char = [' ', #9]; { White space characters to ignore }
cSep = '|'; { Separator character }
cCR = #13; { Carriage return }
iValues: set of Byte = [1, 2]; { Search in property value }
iProperties: set of Byte = [0, 2]; { Search in property name }
iMinWidth = 523; { Width of results grid without scrollbar }
{ Create new expert dialog and find current file }
constructor TfrmPropExplorerExpert.Create(AOwner: TComponent);
var
i: Integer;
sProjectPath, sFilePath, sFileName: String;
slsModified: TStringList;
ediEditor: TIEditorInterface;
fmiForm: TIFormInterface;
begin
inherited Create(AOwner);
{ Display project name }
Caption := Caption + ' - ' + ExtractFileName(ToolServices.GetProjectName);
{ Align results grid columns }
for i := 0 to hdrResults.Sections.Count - 1 do
stgResults.ColWidths[i] := hdrResults.SectionWidth[i] - 1;
{ Create list for modified files }
slsModified := TStringList.Create;
try
sProjectPath := ExtractFilePath(ToolServices.GetProjectName);
{ Load form names into listbox }
for i := 0 to ToolServices.GetFormCount - 1 do
begin
sFilePath := ExtractFilePath(ToolServices.GetFormName(i));
if sFilePath = sProjectPath then
sFilePath := ''
else
sFilePath := ' in ' + sFilePath;
lbxForms.Items.AddObject(ExtractFileName(ToolServices.GetFormName(i)) + sFilePath,
TString.Create(ToolServices.GetFormName(i)));
sFileName := ChangeFileExt(ToolServices.GetFormName(i), '.pas');
if ToolServices.IsFileOpen(sFileName) then { Check if modified }
with ToolServices.GetModuleInterface(sFileName) do
try
ediEditor := GetEditorInterface;
fmiForm := GetFormInterface;
if ediEditor.BufferModified or fmiForm.FormModified then
slsModified.Add(sFileName);
finally
fmiForm.Free;
ediEditor.Free;
Free;
end;
end;
{ If modified files have not been saved - ask for action }
if slsModified.Count > 0 then
case MessageDlg('Some files in this project have'#13#10 +
'been modified but not yet saved.'#13#10 +
'Save these files?', mtConfirmation, mbYesNoCancel, 0) of
mrYes: for i := 0 to slsModified.Count - 1 do
ToolServices.SaveFile(slsModified[i]);
mrNo: { Ignore };
mrCancel: Abort;
end;
finally
slsModified.Free;
end;
{ Highlight current form }
i := lbxForms.Items.IndexOf(ChangeFileExt(ExtractFileName(ToolServices.GetCurrentFile), '.dfm'));
if i > -1 then
lbxForms.Selected[i] := True
else if lbxForms.Items.Count = 1 then
lbxForms.Selected[0] := True;
end;
{ Resize string grid }
procedure TfrmPropExplorerExpert.hdrResultsSizing(Sender: TObject; ASection, AWidth: Integer);
var
i, iWidth: Integer;
begin
stgResults.ColWidths[ASection] := AWidth - 1;
iWidth := 0;
for i := 0 to 2 do
Inc(iWidth, stgResults.ColWidths[i]);
stgResults.ColWidths[3] := iMinWidth - 6 - iWidth;
end;
{ Set all/none buttons appropriately }
procedure TfrmPropExplorerExpert.lbxFormsClick(Sender: TObject);
var
i: Integer;
begin
btnAll.Enabled := False;
btnNone.Enabled := False;
with lbxForms do
for i := 0 to Items.Count - 1 do
begin
if not Selected[i] then
btnAll.Enabled := True;
if Selected[i] then
btnNone.Enabled := True;
if btnAll.Enabled and btnNone.Enabled then
Break;
end;
EnableLocate(Sender);
end;
{ Select all forms for searching }
procedure TfrmPropExplorerExpert.btnAllClick(Sender: TObject);
var
i: Integer;
begin
for i := 0 to lbxForms.Items.Count - 1 do
lbxForms.Selected[i] := True;
lbxForms.TopIndex := 0;
lbxFormsClick(Sender);
ActiveControl := cmbValue;
end;
{ Clear all forms from searching }
procedure TfrmPropExplorerExpert.btnNoneClick(Sender: TObject);
var
i: Integer;
begin
for i := 0 to lbxForms.Items.Count - 1 do
lbxForms.Selected[i] := False;
lbxForms.TopIndex := 0;
lbxFormsClick(Sender);
end;
{ Enable Locate button if applicable }
procedure TfrmPropExplorerExpert.EnableLocate(Sender: TObject);
begin
btnLocate.Enabled := ((cmbValue.Text <> '') and (lbxForms.SelCount > 0));
end;
{ Start processing }
procedure TfrmPropExplorerExpert.btnLocateClick(Sender: TObject);
begin
try
Screen.Cursor := crHourglass;
btnLocate.Enabled := False;
if cmbValue.Items.IndexOf(cmbValue.Text) = -1 then
cmbValue.Items.Add(cmbValue.Text);
ProcessFiles(cmbValue.Text, lbxForms);
finally
Screen.Cursor := crDefault;
btnLocate.Enabled := True;
end;
end;
{ Scan the file for the requested property name and/or value }
procedure TfrmPropExplorerExpert.ProcessFiles(sMatchValue: String; lbxForms: TListBox);
var
stmForm: TFileStream; { Input resource file }
stmMemory: TMemoryStream; { Converted to text }
sLine: String; { Current line from file }
sProperty: String; { Current property - for lists }
sValue: String; { Value of current property }
slsTokens, slsObjects, slsCalls: TStringList; { Working lists }
iForm, iSep1, iSep2, iSep3, iSep4: Integer;
bInList, bInCollection, bFound: Boolean;
{ Break line up into tokens - separated by white space }
procedure GetTokens;
var
iPos, iLen: Integer;
sToke